#include <iostream>
#include "PGPLOT_cmap.h"
#include "cpgplot.h"

using namespace std;

PGPLOT_cmap::PGPLOT_cmap() {
	cout << "PGPLOT_cmap::PGPLOT_cmap Default Constructor" << endl;
}
PGPLOT_cmap::~PGPLOT_cmap() {
	cout << "PGPLOT_cmap::PGPLOT_cmap Default Destructor" << endl;
}


PGPLOT_gray::PGPLOT_gray() {
	cout << "PGPLOT_gray::PGPLOT_gray Default Constructor" << endl;
}
PGPLOT_gray::~PGPLOT_gray() {
	cout << "PGPLOT_gray::PGPLOT_gray Default Destructor" << endl;
}


float PGPLOT_gray::set_range(float min, float max){

	float range = max-min;
	float perlevel = range/num_indices;
	return perlevel;
}

	
void PGPLOT_gray::build_table(int levels) {

	/* default gray scale */
	
	float red=1;
	float green=1;
	float blue=1;

	int min_index=0;

	int max_index=0;

	/* check how many levels our device has */

	cpgqcol(&min_index,&max_index);
	if (levels > max_index+1 || levels == 0) {
		num_indices = (max_index - min_index);
		cerr << "Rescaling to " << num_indices << " levels." << endl;
	}
	else {
		num_indices = levels;
	}

	float increment = 1.0/num_indices;
	
	for (int index=2; index < num_indices; index++) {

		/* actual pgplot call */

		cpgscr(index,red,green,blue);

		red = red-increment;
		green = green-increment;
		blue = blue-increment;

	}

}

